package com.wwy.readwrite.config;

/**
 * @author 王伟羽
 * @program: readwrite-demo
 * @description:
 * @create: 2025/02/08
 */

import com.wwy.readwrite.utlis.DynamicDataSourceHolder;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/**
 * 数据源路由器，用于自动将sql语句分发给对应的数据源
 * 比如将增删改sql语句分发给主库数据源，将查询sql语句分发给从库数据源
 */
public class DynamicDataSource extends AbstractRoutingDataSource {
    @Override
    protected Object determineCurrentLookupKey() {
        return DynamicDataSourceHolder.getDbType();
    }
}
